//
//  JCCUser.swift
//  剂查查
//
//  Created by xianquan on 2024/12/12.
//  Copyright © 2024 shipin. All rights reserved.
//

import CommonTools
import HandyJSON


final class JCCUser: HandyJSON, Codable {
    var id = 0
    var age = 0
    var deleted = 0
    var gender = 0
    var headimg = ""
    var realname = ""
    var remark = ""
    
    var showGender: String {
        gender > 0 ? (gender == 1 ? "男" : "女") : "未知"
    }

    public func didFinishMapping() {
        encode(to: .disk, key: .userInfo)
    }
    
    static func loadUserInfo(callback: @escaping () -> () = {}) {
        NetworkRequest<JCCUser>.request(networkType: .getUserInfo) { result in
            switch result {
            case .success(let response):
                XWLog(value: "获取用户信息成功")
                if let user = response {
                    JCCManager.shared.user = user
                }
                callback()
            case .failure(let error):
                XWLog(value: "获取用户信息失败:\(error)")
            }
        }
    }
}
